package com.oa.android.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.xunxian.HomeActivity;
import com.oa.android.R;
import com.oa.android.activity.CgxActivity;
import com.oa.android.activity.FileMangeActivity;
import com.oa.android.activity.GGaoActivity;
import com.oa.android.activity.GongdActivity;
import com.oa.android.activity.GwsfActivity;
import com.oa.android.activity.QianDaoActivity;
import com.oa.android.activity.RicActivity;
import com.oa.android.activity.VoteListActivity;
import com.oa.android.activity.WorkMangeActivity;
import com.oa.android.utils.UConstants;
import com.oa.android.utils.Util;
import com.watermeter.android.MainActivity;

import java.util.Calendar;

/**
 * 工作
 * Created by zouqh on 2016/6/10.
 */
public class WorkFragment extends Fragment implements View.OnClickListener {

    View workView;
    private LinearLayout[] layout = new LinearLayout[13];
    private int[] layoutId = {R.id.layout1, R.id.layout2, R.id.layout3, R.id.layout4, R.id.layout5, R.id.layout6, R.id.layout7,
            R.id.layout8,  R.id.layout9,R.id.layout10,R.id.layout11,R.id.layout12,R.id.layout13};
    private TextView name;
    private TextView bumen,comName;
    private TextView ril;
    private Calendar calendar ;//日历


    //重写setMenuVisibility方法，不然会出现叠层的现象
    @Override
    public void setMenuVisibility(boolean menuVisibile) {
        super.setMenuVisibility(menuVisibile);
        if (this.getView() != null) {
            this.getView().setVisibility(menuVisibile ? View.VISIBLE : View.GONE);

        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        workView = inflater.inflate(R.layout.work_layout, container, false);
        name=(TextView)workView.findViewById(R.id.name);
        name.setText("姓名："+UConstants.EmpName);
        bumen=(TextView)workView.findViewById(R.id.bm);
        ril=(TextView)workView.findViewById(R.id.ril);
        comName=(TextView)workView.findViewById(R.id.comName);
        bumen.setText("部门："+UConstants.USERBUMEN);
        comName.setText(""+UConstants.ComName);
        for (int i = 0; i < layout.length; i++) {
            layout[i] = (LinearLayout) workView.findViewById(layoutId[i]);
            layout[i].setOnClickListener(this);
        }

        return workView;
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.e("onResume----","AAAAAAAAAAAAAAAAAAAAA");
        calendar = Calendar.getInstance();
        int m=calendar.get(Calendar.MONTH)+1;
        ril.setText(m+"."+calendar.get(Calendar.DAY_OF_MONTH));
    }

    @Override
    public void onClick(View v) {
        Intent intent=new Intent();
        switch (v.getId()) {
            case R.id.layout1:
                intent.setClass(getActivity(), GGaoActivity.class);
                startActivity(intent);
                break;
            case R.id.layout2:
                intent.setClass(getActivity(), GwsfActivity.class);
                startActivity(intent);
                break;
            case R.id.layout3:
                intent.setClass(getActivity(), FileMangeActivity.class);
                startActivity(intent);
                break;
            case R.id.layout4:
                intent.setClass(getActivity(), CgxActivity.class);
                intent.putExtra("type","1");
                startActivity(intent);
                break;
            case R.id.layout5:
                intent.setClass(getActivity(), CgxActivity.class);
                intent.putExtra("type","2");
                startActivity(intent);
                break;
            case R.id.layout6:
                intent.setClass(getActivity(), CgxActivity.class);
                intent.putExtra("type","3");
                startActivity(intent);
                break;
            case R.id.layout7:
                intent.setClass(getActivity(), RicActivity.class);
                startActivity(intent);
                break;
            case R.id.layout8:
                intent.setClass(getActivity(), VoteListActivity.class);
                startActivity(intent);
                break;
            case R.id.layout9:
                intent.setClass(getActivity(), WorkMangeActivity.class);
                startActivity(intent);
                break;
            case R.id.layout10:
                if (Util.NoNull(UConstants.CB_ROOT)){
                    intent.setClass(getActivity(), MainActivity.class);
                    startActivity(intent);
                }else{
                    Toast.makeText(getActivity(),"无抄表功能权限",Toast.LENGTH_SHORT).show();
                }

                break;
            case R.id.layout11:
                if (Util.NoNull(UConstants.XX_ROOT)) {
                    intent.setClass(getActivity(), HomeActivity.class);
                    startActivity(intent);
                }else{
                    Toast.makeText(getActivity(),"无巡线功能权限",Toast.LENGTH_SHORT).show();
                }
                break;

            case R.id.layout12:
                intent.setClass(getActivity(), GongdActivity.class);
                startActivity(intent);
                break;
            case R.id.layout13:
                intent.setClass(getActivity(), QianDaoActivity.class);
                startActivity(intent);
                break;
        }
    }
}
